package Lee_code;

import java.util.Deque;
import java.util.LinkedList;

public class Lee_20
{
    public boolean isValid(String s)
    {
        char[] in = s.toCharArray();
        Deque<Character> deque = new LinkedList<>();
        for (char i: in)
        {
            if(i=='('||i=='{'||i=='[')
            {
                deque.push(i);
            }
            else
            {
                char temp = deque.peek();
                if (temp == '(' && i == ')'||temp == '{' && i == '}'||temp == '[' && i == ']')
                    deque.pop();
            }
        }
        return deque.isEmpty();
    }
}
